// #ifndef VUE3
import Vue from 'vue'
import App from './App'

Vue.config.productionTip = false

import cuCustom from './components/cu-custom'
import TopPage from './components/Top-Page/Top-Page.vue';

Vue.component('cu-custom', cuCustom)
Vue.component('TopPage', TopPage)



App.mpType = 'app'

const app = new Vue({
  ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
  createSSRApp
} from 'vue'
import App from './App.vue'
import cuCustom from './components/cu-custom'
import util from '@/utils/utils.js'
import {
  Toast
} from '@/utils/fun'
import store from './store'
import '@/utils/request'
import api from '@/api/index.js';
import socketIO from '@/common/socket.js';
import Empty from "@/components/Empty.vue" //通用空状态
import Tags from "@/components/Tags.vue" //通用标签

// android点击手机物理返回键退出app bug解决
document?.addEventListener("plusready", function() {
  plus.key?.addEventListener('backbutton', function() {
    window.history.go(-1);
  }, false);
})

// var first = 0;
// document?.addEventListener(
//   "plusready",
//   function() {
//     plus.key?.addEventListener(
//       "backbutton",
//       function() {
//         if (
//           window.history.state.current == "/" ||
//           window.history.state.current == "/index" ||
//           router.currentRoute.value.name == "index" ||
//           router.currentRoute.value.name == "/" ||
//           !window.history.state.back
//         ) {
//           //首次按键，提示‘再按一次退出应用’
//           if (!first) {
//             first = new Date().getTime();
//             Toast("再按一次退出应用");
//             setTimeout(function() {
//               first = 0;
//             }, 2000);
//           } else {
//             if (new Date().getTime() - first < 2000) {
//               plus.runtime.quit();
//             }
//           }
//         } else {
//           router.go(-1);
//         }
//       }, {
//         passive: false
//       }
//     );
//   }, {
//     passive: false
//   }
// );

export function createApp() {
  const app = createSSRApp(App)
  app.config.globalProperties.appStatus = true;
  app.config.globalProperties.$util = util;
  app.config.globalProperties.$api = api;
  app.config.globalProperties.$store = store;
  app.config.globalProperties.$Toast = Toast;
  app.config.globalProperties.socketIo = new socketIO()
  app.component('cu-custom', cuCustom)
  app.component('Empty', Empty)
  app.component('Tags', Tags)
  app.use(store)
  return {
    app
  }
}
// #endif